package com.vma.jifu.backsys.config;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.sun.net.httpserver.HttpServer;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by kitabi on 2017/8/8.
 */
public class LoginInterceptor implements Interceptor {



    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        HttpServletRequest target = controller.getRequest();

        String url = target.getRequestURI();

        String staffid =controller.getSessionAttr("staffId");
        if(staffid == null || "".equals(staffid)){

            if(url.indexOf("login")>-1 || url.indexOf("index/index")>-1){
                inv.invoke();
            }else{
                controller.renderJson();
                controller.redirect("/newshop/login/index.html");
            }


        }else{
            inv.invoke();
        }

    }
}
